package routers

import (
	"fmt"
	"littleblog/dbs"

	"github.com/labstack/echo"
)

//@router /message/new/:key [post]
func CommentSave(c echo.Context) error {
	var resp ResponseData
	resp.Code = RECODE_OK
	defer JsonWrite(c, &resp)
	note := dbs.Note{}
	note.Key = c.Param("key")
	err := dbs.Dbx.GetNoteByKey(&note)
	if err != nil {
		resp.Code = RECODE_DBERR
		fmt.Println("Failed to GetNoteByKey", err)
		return err
	}
	/*
		MsgID   string `json:json:"msg_key"`
		UserID  int    `json:"user_id"`
		NoteKey string `json:"note_key"`
		Content string `json:"content"`
		Praise  int    `json:"praise"`
	*/
	msg := dbs.Message{
		UserID:  note.UserID,
		NoteKey: note.Key,
		Content: note.Summary,
	}
	_, err = dbs.Dbx.SaveComment(msg)
	if err != nil {
		resp.Code = RECODE_DBERR
		fmt.Println("Failed to SaveComment", err)
		return err
	}
	//resp.Action =

	return nil
}
